package com.md.drcs.dicom.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.md.common.dto.page.ResponseQuery;
import com.md.drcs.dicom.dao.PatientDao;
import com.md.drcs.dicom.dao.StudyDao;
import com.md.drcs.dicom.dto.PatientStudyDTO;
import com.md.drcs.dicom.entity.PatientEntity;
import com.md.drcs.dicom.req.PatientStudyQueryReq;
import com.md.drcs.dicom.service.PatientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("patientService")
public class PatientServiceImpl implements PatientService {

    @Autowired
    private StudyDao studyDao;

    @Autowired
    private PatientDao patientDao;

    @Override
    public ResponseQuery<PatientStudyDTO> findPatientStudy(PatientStudyQueryReq req) {
        Page<Object> page = PageHelper.offsetPage(req.getStart(), req.getPageSize());
        List<PatientStudyDTO> patientStudy = studyDao.findPatientStudy(req);
        return new ResponseQuery<>(patientStudy, page.getTotal(), page.getPages());
    }

    @Override
    public PatientEntity get(Long id) {
        return patientDao.selectByPrimaryKey(id);
    }

}
